package com.csx.springcloud.configcenter.apollo.sample.listener;

import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import org.springframework.cloud.context.scope.refresh.RefreshScope;

/**
 * @author cuisongxu
 * @date 2023/3/5 18:52
 */
public class ApolloConfigChangeListener implements ConfigChangeListener {

    private final RefreshScope refreshScope;

    public ApolloConfigChangeListener(RefreshScope refreshScope) {
        this.refreshScope = refreshScope;
    }

    @Override
    public void onChange(ConfigChangeEvent configChangeEvent) {
        System.out.println("apollo config change traffic");
//        Set<String> changedKeys = configChangeEvent.changedKeys();
//        // TODO 记得做过滤,只有相应key发生变更时才触发 refreshAll()
        refreshScope.refreshAll();
    }
}
